package com.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.dao.VersionDao;
import com.enetiy.Area;
import com.enetiy.Version;

public class VersionDaoImpl extends HibernateDaoSupport implements VersionDao {

	@Override
	public List<Version> selectVersionList() throws Exception {
		return this.getHibernateTemplate().find("from Version");
		
	}

	@Override
	public void updateVersion(Version v) throws Exception {
		this.getHibernateTemplate().update(v);
	}

	@Override
	public void deleteVersion(Version v) throws Exception {
		this.getHibernateTemplate().delete(v);

	}

	@Override
	public void insertVersion(Version v) throws Exception {
		this.getHibernateTemplate().save(v);

	}

	

	@Override
	public List<Version> selectVersion(int status,int type,int apptype) throws Exception {
		Query query = this.getSession().createQuery("from Version where status=? and device_type=? and app_type=?");
		query.setParameter(0, status);
		query.setParameter(1, type);
		query.setParameter(2, apptype);
		List<Version> list = query.list();
		return list;
	}

	@Override
	public Version selectVersion(String ver, int type,int apptype) throws Exception {
		Query query = this.getSession().createQuery("from Version where versionNum=? and device_type=? and app_type=?");
		query.setParameter(0, ver);
		query.setParameter(1, type);
		query.setParameter(2, apptype);
		List<Version> list = query.list();
		return list.isEmpty()?null:list.get(0);
	}


}
